package com.ischoolbar.programmer.utils;

import com.ischoolbar.programmer.entity.admin.Menu;

import java.util.ArrayList;
import java.util.List;

public class MenuUtil {
    /*
    * 查找所有顶级菜单
    * */
    public static List<Menu> findTopMenuList(List<Menu> menuList) {
        List<Menu> retMenuList = new ArrayList<>();
        for (Menu menu : menuList) {
            if (menu.getParentId() == 0) {
                retMenuList.add(menu);
            }
        }
        return retMenuList;
    }

    /*
    * 查找所有二级菜单
    * */
    public static List<Menu> findAllSecondMenu(List<Menu> menuList) {
        List<Menu> retSecondMenuList = new ArrayList<>();
        List<Menu> allTopMenuList = findTopMenuList(menuList);
        for (Menu allMenu : menuList) {
            for (Menu topMenu : allTopMenuList) {
                if(allMenu.getParentId() == topMenu.getId()) {
                    retSecondMenuList.add(allMenu);
                    break;
                }
            }
        }
        return retSecondMenuList;
    }

    /*
    * 查找所有三级菜单
    * */
    public static List<Menu> findAllThirdList(List<Menu> allMenuList, Integer secondMenuId) {
        List<Menu> retThirdMenuList = new ArrayList<>();
        for (Menu menu : allMenuList) {
            if (menu.getParentId() == secondMenuId) {
                retThirdMenuList.add(menu);
            }
        }
        return retThirdMenuList;
    }
}
